import { IFeidaoAiNodejsComponent } from '@dfeidao/atom-nodejs/interfaces';
import nodejs from '@dfeidao/atom-nodejs/msg/nodejs';
import render from '@dfeidao/atom-nodejs/render/render';
import p001 from './p001';
import p003 from './p003';
import format from '@dfeidao/atom-web/dt/format';
import set from '@dfeidao/atom-web/global/set';


export default async function na001(fd: IFeidaoAiNodejsComponent) {
	// todo
	// todo
	const res = await nodejs<{ dt: Array<{ work_bill_no: string, job_content: string, cust_name: string, project_name: string, project_no: string, create_time: number, source_type: string, work_order_status: string }>; c: number }>(fd.data.actionid, fd.data.sessionid, "test-web/zj-000003/s001", { filter: { Pn: 1 } });
	const ret = Array();
	for (let i = 0; i < res.dt.length; i++) {
		if (res.dt[i].source_type == "1") {
			res.dt[i].source_type = "总服务台";
		} else if (res.dt[i].source_type == "2") {
			res.dt[i].source_type = "服务台";

		} else if (res.dt[i].source_type == "3") {
			res.dt[i].source_type = "客户报障";

		} else {
			res.dt[i].source_type = "内部报障";
		}

	}
	for (let i = 0; i < res.dt.length; i++) {

		if (res.dt[i].work_order_status == "1") {
			res.dt[i].work_order_status = "结单";
		} else if (res.dt[i].work_order_status == "2") {
			res.dt[i].work_order_status = "完成";

		} else if (res.dt[i].work_order_status == "3") {
			res.dt[i].work_order_status = "挂起";

		} else if (res.dt[i].work_order_status == "4") {
			res.dt[i].work_order_status = "未派单";
		} else {
			res.dt[i].work_order_status = "进行中";
		}
	}
	const p = res.dt.map((n) => {
		return { ...n, create_time: format(n.create_time, 2) }
	})
	for (let i = 0; i < res.dt.length; i++) {
		ret[i] = res.dt[i].project_no;

	}
	
	const res1 = await nodejs<{ d1: Array<{ equip_depart_no: string, project_no: string, equip_depart_name: string }> }>(fd.data.actionid, fd.data.sessionid, "test-web/zj-000003/s002", {
		filter: {
			project_no: ret
		}
	});
	set('ret',ret);
	const arr = Array()
	for (let index = 0; index < res.dt.length; index++) {
		for (let i = 0; i < res1.d1.length; i++) {
				if (res.dt[index].project_no == res1.d1[i].project_no) {
				arr[index] = {
					work_bill_no: res.dt[index].work_bill_no, job_content: res.dt[index].job_content, source_type: res.dt[index].source_type,
					cust_name: res.dt[index].cust_name, project_name: res.dt[index].project_name, work_order_status: res.dt[index].work_order_status, create_time: p[index].create_time, equip_depart_name: res1.d1[i].equip_depart_name
				}

			}
		}
	}

if(arr.length>=20){
	render(fd.data.node,res.c,p003,'p003');

}
render(fd.data.node, arr, p001, 'p001');


}



